package com.example.springboot;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * @Author：伐柯梦姝
 * @Package：com.example.springboot
 * @Project：springboot
 * @name：test1
 * @Date：2025/3/30 16:51
 * @Filename：test1
 * @for:
 */
//@SpringBootTest
public class test1 {
    @Test
    public void stringToDoublePoints() {
        String points = "[[1,2], [3,4], [5,6]]";
        String replace = points.replace("[", "").replace("]", "");
        System.out.println(replace);
        String[] split = replace.split(",");
        ArrayList<Double> doubles = new ArrayList<>();
        Arrays.stream(split).forEach(s -> doubles.add(Double.parseDouble(s)));
        System.out.println(doubles);   //doubles

        Double[][] doublePoints = new Double[doubles.size() / 2][2]; //doubles即前面返回的double集合
        int count = 0;
        for (Double[] doublePoint : doublePoints) {//这个循环用于转换  doublePoints为转换后的结果
            doublePoint[0] = doubles.get(count);
            doublePoint[1] = doubles.get(count + 1);
            count += 2;
        }
        for (int i = 0; i < doublePoints.length; i++) {//这个循环用于输出结果
            System.out.print(doublePoints[i][0] + " " + doublePoints[i][1]);
            System.out.println();
        }
    }


    @Test
    public void test2(){
        Double[][] aa = new Double[][]{{1d, 2d}, {1.1, 1.2}, {1.3, 1.4}};

        for (int i = 0; i < aa.length; i++) {
            for (int j = 0; j < aa[i].length - 1; j++) {
                Double aDouble = aa[i][j];
                Double aDouble1 = aa[i][j + 1];
                System.out.println("经度= " + aDouble + "  纬度= " + aDouble1);
            }
        }

    }





}
